package com.fowo.api.shein.controller;

import com.fowo.api.common.model.R;
import com.fowo.api.model.shop.info.ShopInfoVo;
import com.fowo.api.shein.service.SheinAuthService;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/shein")
public class SheinAuthController {

    @Resource
    private SheinAuthService sheinAuthService;

    @ApiOperation(value = "店铺应用授权", httpMethod = "POST")
    @PostMapping(path = {"/authorization"})
    public R<String> getUrl(@RequestBody ShopInfoVo model){
        return R.data(() -> sheinAuthService.getAuthorizateUrl("NAME_"+model.getShopName()));
    }

    @GetMapping("/callback")
    public R callback(String appid, String tempToken, String state){
        return R.run(() -> sheinAuthService.getByToken(appid, tempToken, state));
    }

    @Operation(summary = "刷新授权")
    @PostMapping("/refresh")
    public R<String> getAuthorizationUrl(@RequestBody ShopInfoVo model){
        return R.data(() -> sheinAuthService.getAuthorizateUrl("ID_"+model.getId()));
    }

}
